package com.sky.controller.user;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("userShopController")
@RequestMapping("/user/shop")
public class ShopController {
    public static String KEY = "SHOP_STATUS";

    @Autowired
    RedisTemplate redisTemplate;
    @GetMapping("/status")
    public Result<Integer> queryShopStatus(){
        Object obj = redisTemplate.opsForValue().get(KEY);
        Integer val = null;
        if (obj != null) {
            if (obj instanceof String) {
                val = Integer.parseInt((String) obj);
            } else {
                val = (Integer) obj;
            }
        }
        if(val == null){
            redisTemplate.opsForValue().set(KEY,"0");
            val = 0;
        }
        return Result.success(val);
    }
}
